package com.usc.web;

import com.usc.web.feign.UserAction;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.usc.entity.User;
import java.net.http.HttpRequest;

@RestController
// 配置刷新动态
@RefreshScope
public class IndexController {
   @RequestMapping("index")
    public String index(HttpServletRequest request) {
        return "hello index " + request.getServerPort();
    }

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("fromuser")
    public String user(){
         String res = restTemplate.getForObject("http://user/user", String.class);
        return res;
    }

    @Autowired
    UserAction userAction;

    @RequestMapping("fromuserbyfeign")
    public String userByFeign(){
        return userAction.user();
    }

    @RequestMapping("add")
    public String add(int a, int b){
        return "result = " + userAction.add(a, b);
    }

    @RequestMapping("hello")
    public String hello(String name){
        return userAction.hello(name);
    }

    @RequestMapping("emp1")
    public User emp1(){
        User user = new User();
        user.setId(1);
        user.setName("emp1");
        user.setAge(10);
        user.setSex("男");
        return userAction.emp1(user);
    }

    @RequestMapping("emp2")
    public User emp2(){
        User user = new User();
        user.setId(1);
        user.setName("emp2");
        user.setAge(10);
        user.setSex("男");
        return userAction.emp2(user);
    }

    @RequestMapping("emp11")
    public User emp3(){
        User user = new User();
        user.setId(1);
        user.setName("emp11");
        user.setAge(10);
        user.setSex("男");
        return userAction.emp11(user);
    }

    @RequestMapping("emp22")
    public User emp4(){
        User user = new User();
        user.setId(1);
        user.setName("emp22");
        user.setAge(10);
        user.setSex("男");
        return userAction.emp22(user);
    }


    @Value("${upload.path}")
    String uploadPath;

    @RequestMapping("uploadPath")
    public String uploadPath(){
        return uploadPath;
    }
}
